import datetime
from bson import ObjectId

from config import py_client

class _DataQuery(object):
    """
    从mongodb查询
    """
    db = py_client.miaozhen

    def data_query(self):
        pres_obj = self.db.SFLZ_Prescription.find({
            "prescription_time":{
                "$gte":datetime.datetime.strptime("2019-01-01 00:00:00", "%Y-%m-%d %H:%M:%S")
            }
        })
        i = 1
        for obj in pres_obj:
            medicine_obj = self.db.SFLZ_Medicine.find_one({"prescription_id":ObjectId(obj["_id"])})
            print("----------------------", i)
            if not medicine_obj:
                i += 1
                print("没有药品的处方id",obj["_id"])

        return


def main():
    DataQuery = _DataQuery()
    DataQuery.data_query()
